<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Script 4.1</title>
<link href="../css/global.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function dateString(date,string) {
		/* key for creating string
			%Y = 2008
			%y = 08
			%M = January
			%m = Jan
			%N = 01 (month)
			%n = 1 (month)
			%W = Monday
			%w = Mon
			%D = 05 (day of month)
			%d = 5 (day of month)
		*/
		var year=date.getFullYear();
		var month=date.getMonth();
		var realMonth=month+1;
    var fillMonth
		if (realMonth<10) {
			fillMonth = '0' + realMonth;
		} else {
			fillMonth = realMonth;
		}
		var months = ['January','February','March','April','May',
									'June','July','August','September',
									'October','November','December'];
		var monthName=months[month];
		var day=date.getDate();
    var fillDate
		if (day<10) {
			fillDate='0' + day;
		} else {
			fillDate=day;
		}
		var weekday=date.getDay();
		var weekdays = ['Sunday','Monday','Tuesday','Wednesday',
								'Thursday','Friday','Saturday'];
		var dayName=weekdays[weekday];
		
		
		//year
		string = string.replace(/%Y/g,year); // 2008
		string = string.replace(/%y/g,year.toString().slice(-2)); //08
		//month
		string = string.replace(/%M/g,monthName); //January
		string = string.replace(/%m/g,monthName.slice(0,3)); //Jan
		string = string.replace(/%N/g,fillMonth); // 01
		string = string.replace(/%n/g,realMonth); // 1
		//day of week
		string = string.replace(/%W/g,dayName); //Monday
		string = string.replace(/%w/g,dayName.slice(0,3)); //Mon
		//day of month
		string = string.replace(/%D/g,fillDate); //05
		string = string.replace(/%d/g,day); // 5
		return string;
	}
</script>
</head>
<body id="twoCol">
<div id="container">
  <div id="banner"><img src="../images/banner.png" alt="JavaScript: The Missing Manual" width="760" height="65"><span id="badge"><a href="http://www.sawmac.com/missing/js/"></a></span></div>
  
  <div id="contentWrap">
  <div id="main">
  <h1>Today&#8217;s Date</h1>
  <p>
  <script type="text/javascript">
	var today = new Date();
	var message = dateString(today, 'Today is %W, %M %D, %Y');
	document.write(message);
	</script>
  </p>
</div>
  <div id="sidebar">
   <h2>Script 4.1</h2>
</div>
  </div>
  <div id="footer"><em>&#8220;Building Interactive Web Sites with JavaScript&#8221;</em></div>
</div>
</body>
</html>
